import { useGetAllCompletedTasks } from "@/entities/AllCompletedTasks/model/useGetAllCompletedTasks";
import { useGetCurrentUser } from "@/entities/user/model/useGetCurrentUser";
import UiProfile from "@/entities/user/ui/UiProfile";
import LogoutButton from "@/features/logout/ui/LogoutButton";
import UiLogoutBar from "@/features/logout/ui/LogoutButton";
import UiSetRole from "@/features/setRole/ui/UiSetRoleForm";
import { UiButton } from "@/shared/Uikit";
import { UiHeader } from "@/shared/Uikit/UiHeader";
import { PageSpinner } from "@/shared/Uikit/UiPageSpinner";
import Link from "next/link";




export default function Dashboard() {
    const { user, isSuccess, isLoading, errorMessage } = useGetCurrentUser()
    const completedTasks = useGetAllCompletedTasks()
    return (
        <>
            {isLoading &&
                <PageSpinner className='bg-gray-100 opacity-75' />
            }
            {isSuccess && user && completedTasks.isSuccess && completedTasks.completedTasks &&
                <div className="container mx-auto px-4">

                    <header className="flex flex-col items-center py-12">
                        <div className="flex items-center justify-between w-full">
                            <h1 className="text-3xl font-bold text-gray-800">Личный кабинет</h1>
                            <div className="flex items-center">
                                <UiProfile />
                                {(user.role == 'ADMIN' || user.role == 'TEACHER' || user.role == 'MODERATOR') && (
                                    <Link href='/controlpanel' className="btn btn-primary ml-2">
                                        <UiButton variant='secondary'>
                                            Панель управления
                                        </UiButton>
                                    </Link>
                                )}
                                <LogoutButton className="btn btn-primary ml-2" />
                            </div>
                        </div>
                    </header>
                    <section className='py-8 flex justify-around'>
                        <div className="bg-white rounded-lg shadow-md p-6 text-center">
                            <h3 className="text-lg font-medium text-gray-800">Дисциплин завершено:</h3>
                            <span className="text-4xl font-bold text-green-500">{completedTasks.completedTasks.completedDisciplines.length}</span>
                        </div>
                        <div className="bg-white rounded-lg shadow-md p-6 text-center">
                            <h3 className="text-lg font-medium text-gray-800">Тем завершено:</h3>
                            <span className="text-4xl font-bold text-green-500">{completedTasks.completedTasks.completedThemes.length}</span>
                        </div>
                        <div className="bg-white rounded-lg shadow-md p-6 text-center">
                            <h3 className="text-lg font-medium text-gray-800">Уроков завершено:</h3>
                            <span className="text-4xl font-bold text-green-500">{completedTasks.completedTasks.completedLessons.length}</span>
                        </div>
                    </section>

                    <section className='py-8'>
                        <div className="bg-white rounded-lg shadow-md p-6 text-center">
                            <h3 className="text-lg font-medium text-gray-800">Вы заработали:</h3>
                            <span className="text-4xl font-bold text-green-500">1200 баллов</span>
                        </div>
                    </section>
                    {/* <UiSetRole /> */}
                    <section className='py-8 flex w-full justify-center'>
                        <Link href='/disciplines'>
                            <UiButton variant='primary' className=''>
                                Начать обучение
                            </UiButton>
                        </Link>
                    </section>

                </div>
            }
        </>

    )
}